<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>全所收支明细</title>
    <link rel="stylesheet" href="../../layuiadmin/js/finance/js/bootstrap/css/bootstrap.min.css" />
    <script type="text/javascript" src="../../layuiadmin/js/finance/js/jquery.min.js" ></script>
    <script type="text/javascript" src="../../layuiadmin/js/finance/js/bootstrap/js/bootstrap.js" ></script>
    <script type="text/javascript" src="../../layuiadmin/js/finance/js/jquery.table2excel.js"></script>
    <script>
        $(document).ready(function(){
            $.post("http://localhost:8080/financePayoutController/payouttypelist",function(msg){
                for(var i=0;i<msg.length;i++){
                    var payoutType=$("#payoutType");
                    if(msg[i].pid==0){
                        var op=$("<option value='"+msg[i].payoutTypeId+"'>"+msg[i].payoutName+"</option>");
                    }else if(msg[i].pid!=100103){
                        var op = $("<option value='"+msg[i].payoutTypeId+"'>"+"&nbsp&nbsp----" + msg[i].payoutName + "</option>");
                    }else{
                        var op = $("<option value='"+msg[i].payoutTypeId+"'>"+"&nbsp&nbsp&nbsp&nbsp----" + msg[i].payoutName + "</option>");
                    }
                    payoutType.append(op);
                }
            });
            $.post("http://localhost:8080/financePayoutController/caseid",function(msg){
                for(var i=0;i<msg.length;i++){
                    var caseid=$("#caseid");
                    if(msg[i].ppid==0){
                        var op=$("<option value='"+msg[i].caseTypeid+"'>"+msg[i].typeName+"</option>");
                    }else{
                        var op=$("<option value='"+msg[i].caseTypeid+"'>" + "&nbsp&nbsp----" +msg[i].typeName+"</option>");
                    }
                    caseid.append(op);
                }
            });
            $.post("http://localhost:8080/financePayoutController/paytype",function(msg) {
                for(var i=0;i<msg.length;i++){
                    var paytype=$("#paytype");
                    var op=$("<option value='"+msg[i].payId+"'>"+msg[i].payType+"</option>");
                    paytype.append(op);
                }
            });
            list();

        });
        function  list() {
            var payoutType=$("#payoutType").val();
            var caseId=$("#caseid").val();
            var paytype=$("#paytype").val();
            var enteringdate=$("#enteringdate").val();
            var inputdate=$("#inputdate").val();
            $.post("http://localhost:8080/financePayoutController/payoutlist",
                {"payoutType": payoutType, "caseId": caseId, "paytype": paytype,"inputdate":inputdate,"enteringdate":enteringdate},
                function (msg) {
                    var tab = $("#tab");
                    if(msg.length==0){
                        $("#tab  tr:not(:first)").remove();
                        var tr=$("<tr></tr>");
                        var td=$("<td colspan='9'>没有相关数据</td>");
                        tr.append(td);
                        tab.append(tr);
                    }else {
                        $("#tab  tr:not(:first)").remove();
                        var sum1 = 0;
                        var sum2=0;
                        var tr1 = $("<tr></tr>");
                        for (var i = 0; i < msg.length; i++) {
                            //时间
                            var myDate = new Date(msg[i].inoutDate);
                            var year=myDate.getFullYear();
                            var month=myDate.getMonth()+1;
                            var date=myDate.getDate();
                            var now=year+'-'+month+"-"+date;

                            var tr = $("<tr></tr>");
                            var td=$("<td class='hidden'>"+msg[i].payoutId+"</td>");
                            var td1 = $("<td>" + msg[i].payoutTypeId.payoutName + "</td>");
                            var td2 = $("<td>" + now +"</td>");
                            var name=msg[i].payoutTypeId.payoutName;
                            var td3="";
                            var td4="";
                            if(name.indexOf("收入") >= 0 ) {
                                td3 = $("<td>" + msg[i].inoutMoney + "</td>");
                                td4 = $("<td>-</td>");
                                sum1+=msg[i].inoutMoney;
                            }else{
                                td3 = $("<td>-</td>");
                                td4 = $("<td>" + msg[i].inoutMoney + "</td>");
                                sum2+=msg[i].inoutMoney;
                            }
                            var td5 = $("<td>" + msg[i].payId.payType + "</td>");
                            var td6 = $("<td>" + msg[i].caseId.caseTypeid.typeName + "</td>");
                            var td7 = $("<td>" + msg[i].inoutPerson.empName + "</td>");
                            var td8=$("<td>"+msg[i].payer +"</td>");
                            var td9=$("<td>"+msg[i].remark +"</td>");
                            var td10=$("<td><a onclick='del(this)'>删除</a></td>")
                            tr.append(td);
                            tr.append(td1);
                            tr.append(td2);
                            tr.append(td3);
                            tr.append(td4);
                            tr.append(td5);
                            tr.append(td6);
                            tr.append(td7);
                            tr.append(td8);
                            tr.append(td9);
                            tr.append(td10);
                            tab.append(tr);
                        }
                        tr1.append("<td>总计收支金额</td>");
                        tr1.append("<td></td>");
                        tr1.append("<td>" + sum1 + "(元)</td>");
                        tr1.append("<td>" + sum2 + "(元)</td>");
                        tr1.append("<td></td>");
                        tr1.append("<td></td>");
                        tr1.append("<td></td>");
                        tr1.append("<td></td>");
                        tr1.append("<td></td>");
                        tr1.append("<td></td>");
                        tab.append(tr1);
                    }
                });
        }
        function del(obj) {
            var payoutid = $(obj).parent().parent().find("td").eq(0).text();
            $.post("http://localhost:8080/financePayoutController/delete",{"payoutId":payoutid},function (msg) {
                if(msg!=0){
                    alert("删除成功");
                    list();
                }else{
                    alert("删除失败");
                }
            })
        }
        //导出
        function out() {
            $("#alls").table2excel({
                //table2excel插件的可用配置参数有：
                exclude: ".noExl",//   exclude：不被导出的表格行的CSS class类。
                name: "Excel Document Name",//   name：导出的Excel文档的名称
                filename: "myFileName",//   filename：Excel文件的名称。
                exclude_img: true,//   exclude_img：是否导出图片。
                exclude_links: true,//   exclude_links：是否导出超链接
                exclude_inputs: true//    exclude_inputs：是否导出输入框中的内容
            });
        }
    </script>
</head>
<body>
<div class="container-fluid">
    <form class="form-horizontal form-inline" >
        <div class="row" style="margin-top: 15px">
            <div class="col-lg-12">
                <select class="form-control" id="all">
                    <option value="1">根据案号查询</option>
                    <option value="2">根据收支人查询</option>
                    <option value="3">根据委托人查询</option>
                </select>
                <select class="form-control" id="payoutType" style="width: 400px">
                    <option value="-1">请选择收支类型</option>
                </select>
                <select class="form-control" id="paytype">
                    <option value="-1">请选择支付类型</option>
                </select>
                <select class="form-control" id="caseid">
                    <option value="-1">请选择案件类型</option>
                </select>
                <label for="inputdate">发生日期</label>
                <input class="form-control" type="date" id="inputdate"/>
                <div style="margin-top: 15px">
                    <button type="button" class="btn btn-success" onclick="list()">检索</button>
                    <button type="button"  class="btn btn-default" onclick="out()">导出</button>
                </div>
            </div>
        </div>
        <div style="margin-top: 15px" id="alls">
            <table class="table table-hover table-bordered" style="text-align: center" id="tab">
                <tr style="font-weight: bold">
                    <td>收支类别</td>
                    <td>发生日期</td>
                    <td>收入</td>
                    <td>支出</td>
                    <td>支付方式</td>
                    <td>案号</td>
                    <td>收支人</td>
                    <td>付款人</td>
                    <td>备注</td>
                    <td>操作</td>
                </tr>
            </table>
        </div>
    </form>
</div>
</body>
</html>